<!DOCTYPE html>
<html>
<head>
    <title>挂号--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../layer/layer.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form action="#" id="myForm" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">病历号</td>
        <td><input type="text" name="hosR_id" value="1001" readonly/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">姓名</td>
        <td><input type="text" name="hosR_name" onclick="checkName()" value="陆小凤"/></td>
    </tr>

    <tr>
        <td width="10%" class="tableleft">身份证号</td>
        <td><input type="text" name="hosR_idCar" onclick="checkCar()" value="21324324324"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">挂号费</td>
        <td><input type="text" name="hosR_regPrice" onclick="checkReg()" value="5"/>元</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">社保号</td>
        <td><input type="text" name="hosR_medical" onclick="checkMedical()" value="453253453"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">联系电话</td>
        <td><input type="text" name="hosR_phone" onclick="checkPhone()" value="13543235678"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">是否自费</td>
        <td><input type="radio" name="hosR_selfPrice" value="0"/>否&nbsp;&nbsp;&nbsp;<input type="radio" name="hosR_selfPrice" value="1"/>是</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">性别</td>
        <td><input type="radio" name="hosR_sex" value="1"/>男&nbsp;&nbsp;&nbsp;<input type="radio" name="hosR_sex" value="0"/>女</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">年龄</td>
        <td><input type="text" name="hosR_age" onclick="checkAge()" value="33"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">职业</td>
        <td><input type="text" name="hosR_work" onclick="checkWork()" value="狗仔队"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">初复诊</td>
        <td><input type="radio" name="hosR_lookDoctor" value="0"/>初诊&nbsp;&nbsp;&nbsp;<input type="radio" name="hosR_lookDoctor" value="1"/>复诊</td>
    </tr>
    <!--<tr>
        <td width="10%" class="tableleft">所挂科室</td>
        <td><select><option>急诊科</option><option>骨科</option><option>血液科</option></select></td>
    </tr>-->
    <tr>
        <td width="10%" class="tableleft">指定医生</td>
        <td><select id="doc" name="d_id"></select></td>
    </tr>
	<tr>
        <td width="10%" class="tableleft">备注</td>
        <td><textarea id="hosR_remark" name="hosR_remark">此人疑拟有精神病</textarea></td>
	</tr>
    <tr>
        <td colspan="2">
			<center>
				<button id="btn" class="btn btn-primary" type="button">保存</button> &nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backId">返回列表</button>
			</center>
		</td>
    </tr>
</table>
</form>
</body>
</html>
<script type="text/javascript">
    String.prototype.GetValue= function(para) {
        let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?")+1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }
    $(function () {
        //根据地址获取teamId,如果null则执行增加，否则执行更新
        let url = document.location.toString();//获取URL
        let hosR_id = url.GetValue("hosR_id");
        let pageNum = url.GetValue("pageNum");
        show();
        load(hosR_id);
        $('#backId').click(function(){
            window.location.href="index.html?pageNum="+pageNum;
        });
        $('#btn').click(function(){
            upload(pageNum);
        });
    });

    function show(){
        let windowId = layer.load();
        $.ajax({
            type: "GET",
            url: "/hosregister/show",
            data: "",
            dataType: "json",
            success: function (vo) {
                layer.close(windowId);
                if (vo.code == 200){
                    let list=vo.list;
                    let str="";
                    for(let i=0;i<list.length;i++){
                        let obj=list[i];
                        let d_id=obj.d_id;
                        let d_name=obj.d_name==null?'':obj.d_name;
                        str+=' <option value="'+d_id+'">'+d_name+'</option> '
                    }
                    $("#doc").append(str);
                }else {
                    layer.msg(vo.msg)
                }
            }
        });
    }

    function load(hosR_id){
        let windowId = layer.load();
        $.ajax({
            type: "GET",
            url: "/hosregister/queryById/"+hosR_id, //RESTful风格的API定义
            data: "",
            dataType:"json",
            success: function (vo) {
                layer.close(windowId);
                if (vo.code == 200){
                    let obj=vo.obj;
                    let hosR_id=obj.hosR_id;
                    let hosR_name=obj.hosR_name==null?'数据丢失':obj.hosR_name;
                    let hosR_idCar=obj.hosR_idCar==null?'数据丢失':obj.hosR_idCar;
                    let hosR_regPrice=obj.hosR_regPrice;
                    let hosR_medical=obj.hosR_medical==null?'数据丢失':obj.hosR_medical;
                    let hosR_phone=obj.hosR_phone==null?'数据丢失':obj.hosR_phone;
                    let hosR_selfPrice=obj.hosR_selfPrice;
                    let hosR_sex=obj.hosR_sex;
                    let hosR_age=obj.hosR_age;
                    let hosR_work=obj.hosR_work==null?'数据丢失':obj.hosR_work;
                    let hosR_lookDoctor=obj.hosR_lookDoctor;
                    let d_id=obj.doctor.d_id==null?'':obj.doctor.d_id;
                    let d_name=obj.doctor.d_name==null?'':obj.doctor.d_name;
                    let d_keshi=obj.doctor.d_keshi==null?'':obj.doctor.d_keshi;
                    let hosR_remark=obj.hosR_remark==null?'数据丢失':obj.hosR_remark;
                    $("input[name='hosR_id']").val(hosR_id);
                    $("input[name='hosR_name']").val(hosR_name);
                    $("input[name='hosR_idCar']").val(hosR_idCar);
                    $("input[name='hosR_regPrice']").val(hosR_regPrice);
                    $("input[name='hosR_medical']").val(hosR_medical);
                    $("input[name='hosR_phone']").val(hosR_phone);
                    if (hosR_selfPrice=='0'){
                        $("input[name='hosR_selfPrice']")[0].checked='checked';
                    }else {
                        $("input[name='hosR_selfPrice']")[1].checked='checked';
                    }
                    if (hosR_sex=='0'){
                        $("input[name='hosR_sex']")[1].checked='checked';
                    }else {
                        $("input[name='hosR_sex']")[0].checked='checked';
                    }
                    $("input[name='hosR_age']").val(hosR_age);
                    $("input[name='hosR_work']").val(hosR_work);
                    if (hosR_lookDoctor=='0'){
                        $("input[name='hosR_lookDoctor']")[0].checked='checked';
                    }else {
                        $("input[name='hosR_lookDoctor']")[1].checked='checked';
                    }
                    $("#hosR_remark").html(hosR_remark);
                    let opts = document.getElementById("doc");
                    for (let i = 0;i < opts.options.length;i++){
                        if (opts.options[i].value == d_id){
                            opts.options[i].selected =' selected ';
                            break;
                        }
                    }
                }else {
                    layer.msg(vo.msg);
                }
            }
        });
    }

    function upload(pageNum){
        let windowId = layer.load();
        $.ajax({
            type: "POST",
            url: "/hosregister/update",
            data: $("#myForm").serialize()+"&_method=PUT",
            dataType: "json",
            success: function (vo) {
                layer.close(windowId);
                alert(vo.msg);
                if (vo.code == 200){
                    window.location.href="index.html?pageNum="+pageNum;
                }
            }
        });
    }
    function checkName(){
        layer.tips("请输入2-4位有效名字","input:eq(1)",{tipsMore:true,tips:2});
    }
    function checkCar(){
        layer.tips("请输入18位有效身份证号","input:eq(2)",{tipsMore:true,tips:2});
    }
    function checkMedical(){
        layer.tips("请输入6位有效社保号","input:eq(3)",{tipsMore:true,tips:2});
    }
    function checkReg(){
        layer.tips("请输入0-999挂号费","input:eq(4)",{tipsMore:true,tips:2});
    }
    function checkPhone(){
        layer.tips("请输入11位有效手机号","input:eq(5)",{tipsMore:true,tips:2});
    }
    function checkAge(){
        layer.tips("请输入0-99有效年龄","input:eq(10)",{tipsMore:true,tips:2});
    }
    function checkWork(){
        layer.tips("请输入职业","input:eq(11)",{tipsMore:true,tips:2});
    }
</script>